package com.mpsc.singleton.demo.handler.async;

import com.mpsc.singleton.demo.handler.BaseHandler;
import com.mpsc.singleton.demo.handler.BaseHandlerRequest;
import com.mpsc.singleton.demo.util.SpringBeanUtil;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class AsyncManage {

    /**
     * 异步执行器
     */
    @Async("taskExecutor")
    public void asyncExecute(BaseHandlerRequest request) {
        BaseHandler handler = (BaseHandler) SpringBeanUtil.getBean(request.getType());
        handler.execute(request);
    }

    /**
     * 同步执行器
     */
    public void syncExecute(String type) {
        BaseHandler handler = (BaseHandler) SpringBeanUtil.getBean(type);
        handler.execute(type);
    }
//
//    @Async("taskExecutor")
//    public void sendSms(String callPrefix, String mobile, String actionType, String content) {
//        try {
//            Thread.sleep(1000);
//            TaskStatusWebSocket.sendMsgToClient("","");
//
//        } catch (Exception e) {
//            System.out.println(e);
//        }
//    }
//
//    @Async("taskExecutor")
//    public void sendEmail(String email, String subject, String content) {
//        try {
//            Thread.sleep(1000);
//            TaskStatusWebSocket.sendMsgToClient("","");
//        } catch (Exception e) {
//            System.out.println(e);
//        }
//    }
}
